﻿var _CAL = null;
var _input = null;
var _trig = null;
var _format = null;
var _week = false;
var _time = false;
var _lang = "cn";
function loadcalendar(input, trig, format, week, time, language) {
	_input = input;
	_trig = trig;
	_format = format;
	_week = week;
	_time = time;
	_lang = language;
	_CAL = Calendar.setup({
		weekNumbers : _week,
		selectionType : Calendar.SEL_MULTIPLE,
		inputField : _input,
		dateFormat : _format,
		trigger : _trig,
		showTime : _time,
		onSelect : function() {
			this.hide();
		}
	})
	_CAL.setLanguage(_lang);
}
function clearRangeStart(input) {
	document.getElementById(input).value = "";
	_CAL.args.min = null;
	_CAL.redraw();
};
function onWeekSelected(y, week, input, year, month, day) {
	var date = document.getElementById(input);
	var _month;
	var _day;
	if(month<=9){
		_month = "0"+month;
	}else{
		_month = month;
	}
	if(day<=9){
		_day = "0"+day;
	}else{
		_day = day;
	}
	var start_str = year+"-"+_month+"-"+_day;
	var end_date = new Date(start_str);
	var interval = 7*24*60*60*1000;        
    end_date.setTime(end_date.getTime()+interval);
    var end_month = end_date.getMonth()+1;
    var end_day = end_date.getDate();
    if(end_month<=9){
		_end_month = "0"+end_month;
	}else{
		_end_month = end_month;
	}
	if(end_day<=9){
		_end_day = "0"+end_day;
	}else{
		_end_day = end_day;
	}
	date.value = y + "年第" + (week > 9 ? week : "0" + week) + "周" + "(" +year+"-"+_month+"-"+_day +"/"+end_date.getFullYear()+"-"+_end_month+"-"+_end_day+ ")" ;
	_CAL.hide();
};